﻿// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 
// See License.txt in the project root for license information.
using System;
using System.Diagnostics.Tracing;

namespace System.Threading.Actors.Utilities
{
    public static class ConfigurationHelper
    {
        public static void Configure(string configurationString, ActorETWEventListener eventListener)
        {
            if (String.IsNullOrWhiteSpace(configurationString))
                return;

            foreach (String configPiece in configurationString.Split(';'))
            {
                if (configPiece.StartsWith("EventLevel=", StringComparison.InvariantCulture))
                {
                    String levelName = configPiece.Substring(11);
                    EventLevel level = (EventLevel)Enum.Parse(typeof(EventLevel), levelName);
                    eventListener.EnableEvents(ActorETWEventSource.Log, level);
                }
                else
                    throw new NotSupportedException(String.Format("Unsupported configuration string parameter: {0}", configPiece));
            }
        }
    }
}
